package com.eportal.action.background;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.eportal.action.BaseAction;
import com.eportal.domain.SysScoreRule;
import com.eportal.service.SysScoreRuleService;
import com.eportal.util.HomePageConfig;
import com.framework.jqgrid.JqGridPager;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 积分规则管理
 * @author chencheng
 *
 */
public class SysScoreRuleAction extends BaseAction implements ModelDriven<SysScoreRule> {

    /**
	 * @author chencheng
	 */
	private static final long serialVersionUID = 1L;

	private static Logger log = Logger.getLogger(SysScoreRuleAction.class.getName());

    private Map<String, Object> result = new HashMap<String, Object>();
    
    @Autowired
    SysScoreRuleService sysScoreRuleService;
	/**
     * 积分规则管理
     */
    public String listView() {
    	String homePageConfig = HomePageConfig.JIFENGZ;
    	String[] str = homePageConfig.split(",");
		getRequest().setAttribute("mpid", Integer.parseInt(str[0]));
    	getSession().setAttribute("mpid", Integer.parseInt(str[0]));
        return SUCCESS;
    }
    
    /**
     * 积分规则列表
     */
    public void page() throws Exception {
        JqGridPager jqGridPager = new JqGridPager();
        setPage(getRequest(), jqGridPager);
        List<Map<String, Object>> sysScoreRule = sysScoreRuleService.list(jqGridPager);
        jqGridQueryMap(SysScoreRule.class, getRequest(), sysScoreRule, getResponse(), jqGridPager);
    }
    
    /**
     * 积分规则增加
     */
    public String addView() {
        return SUCCESS;
    }
    
    /**
     * 积分规则新增保存
     */
    public void add(){
    	SysScoreRule sysScoreRule = getModel();
    	result = sysScoreRuleService.addMethod(sysScoreRule);
        responseBody(result);
    }
    
    
    /**	
     * 积分规则修改
     */
    public String editView() {
    	SysScoreRule sysScoreRule = sysScoreRuleService.get(getModel().getSid());
        getRequest().setAttribute("sysScoreRule", sysScoreRule);
        return SUCCESS;
    }
    
    /**
     * 积分规则修改保存
     */
    public void update(){
    	SysScoreRule sysScoreRule = getModel();
    	result = sysScoreRuleService.updateMethod(sysScoreRule);
        responseBody(result);
    }
    
    
    /**
     * 删除
     */
    public void delete(){
    	String param_ids = getRequest().getParameter("ids");
    	result = sysScoreRuleService.deleteMethod(param_ids);
        responseBody(result);
    }
    
    
    private SysScoreRule sysScoreRule = new SysScoreRule();

    @Override
    public SysScoreRule getModel() {
        return sysScoreRule;
    }
}
